import unittest
import requests
import jsonpath
import json
from common.config_utils import config
class TestGetAccesstoken(unittest.TestCase):
    def setUp(self) -> None:
        self.host= config.Host
        self.seesion=requests.session()
    def tearDown(self) -> None:
        self.seesion.close()
    @unittest.skip("no reasea")
    def test_creat_user_tag(self):
        self._testMethodName='usertag01'
        self._testMethodDoc='正常创建用户标签'
        url_param = {"grant_type": "client_credential",
                     "appid": "wx71ad615ece9fc889",
                     "secret": "0ea4dbdbc5237ce7fe83def223d80ff2"}
        rp = self.seesion.get('https://%s/cgi-bin/token'%self.host,
                                params=url_param)
        rp_token_j = json.loads(rp.content.decode('utf-8'))
        token = jsonpath.jsonpath(rp_token_j, '$.access_token')[0]


        url_param={"access_token":token}
        header={"content-type":"application/json","accept-language":"zh-CN,zh;q=0.9"}
        data={"tag":{"name":"湖南道"}}
        creat_tag = requests.post(url='https://api.weixin.qq.com/cgi-bin/tags/create',
                                headers=header,
                                params=url_param,
                                data=json.dumps(data,ensure_ascii=False).encode('utf-8')
        )

    @unittest.skip("no reasen")
    def test_creat_user_tag_02(self):
        self._testMethodName = 'usertag01'
        self._testMethodDoc = '创建的标签名长度超长'
        url_param = {"grant_type": "client_credential",
                     "appid": "wx71ad615ece9fc889",
                     "secret": "0ea4dbdbc5237ce7fe83def223d80ff2"}
        rp = self.seesion.get('https://%s/cgi-bin/token' % self.host,
                            params=url_param)
        rp_token_j = json.loads(rp.content.decode('utf-8'))
        token = jsonpath.jsonpath(rp_token_j, '$.access_token')[0]

        url_param = {"access_token": token}
        header = {"content-type": "application/json", "accept-language": "zh-CN,zh;q=0.9"}
        data = {"tag": {"name": "都会发生客户发哈哈哈哈哈哈哈哈哈哈湖南道哈哈哈哈和哈哈哈"}}
        creat_tag = requests.post(url='https://api.weixin.qq.com/cgi-bin/tags/create',
                                   headers=header,
                                   params=url_param,
                                   data=json.dumps(data, ensure_ascii=False).encode('utf-8')
                                      )

